// pages/user/add/index.js
const App = getApp()
Page({
  data:{
    oder_u:0
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    var o_order=options.oder_user
    this.setData({
      oder_u:o_order
    })
  },
  formReset:function(){
    //取消操作
  },
  formSubmit:function(e){
    var data=e.detail.value
    var that=this
    if(data.name == ''||data.phone == '' || data.address == ''){
      wx.showToast({
        title: '请填写相关地址信息',
        icon: 'success',
        image:'../../../assets/images/error-icon.png',
        duration: 2000
      })
      return
    }
    wx.showToast({
        title: '新增中..',
        icon: 'loading',
        duration: 10000
      })
    App.HttpService.addRess({
        name:data.name,
        phone:data.phone,
        address:data.address,
        cityID:data.cityID,
        user_id:wx.getStorageSync('user_id')
    }).then(data=>{
      wx.hideToast()
          if(data.meat.code==0){
               wx.showToast({
                title: '新增成功',
                icon: 'success',
                duration: 2000
              })
              
              setTimeout(function(){
                  wx.hideToast()
                  if(that.data.oder_u==1){
                    wx.navigateTo({
                      url: '../../confirm/index',
                    })
                  }else{
                       wx.navigateBack({
                    delta: 1, // 回退前 delta(默认为1) 页面
                  })
                  }
                 
                },2000)

          }else{
               wx.showToast({
                title: '新增失败',
                icon: 'loading',
                duration: 2000
              })
          }
    })
  }
})